import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:yp/helper.dart';

import 'logic.dart';
import 'state.dart';

class AddInvoiceHeadPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AddInvoiceHeadPage();
  }
}

class _AddInvoiceHeadPage extends State<AddInvoiceHeadPage> {
  final AddInvoiceHeadLogic logic = Get.put(AddInvoiceHeadLogic());
  final AddInvoiceHeadState state = Get.find<AddInvoiceHeadLogic>().state;
  bool isSubmit = false;
  @override
  Widget build(BuildContext context) {
    return GetBuilder<AddInvoiceHeadLogic>(
      builder: (logic) {
        return FlutterEasyLoading(
            child: Scaffold(
          appBar: AppBar(
            centerTitle: true,
            backgroundColor: Colors.white,
            elevation: setWidth(1),
            title: Text(
              state.titleStr,
              style: TextStyle(
                color: Colors.black,
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
            ),
            iconTheme: IconThemeData(
              color: Colors.black,
            ),
          ),
          body: Container(
            child: Column(
              children: [
                Expanded(
                  child: Container(
                    child: ListView(
                      children: [
                        Container(
                          height: setWidth(100),
                          color: Colors.white,
                          padding:
                              EdgeInsets.symmetric(horizontal: setWidth(32)),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              SizedBox(height: setWidth(20)),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  InkWell(
                                    onTap: () {
                                      print('！！！纸质发票选择事件！！！');
                                      if (state.invoiceHeaderBool != '1') {
                                        state.invoiceHeaderBool = '1';
                                        setState(() {});
                                      }
                                    },
                                    child: Row(
                                      children: [
                                        Icon(
                                          state.invoiceHeaderBool == '1'
                                              ? Icons.check_circle
                                              : Icons.panorama_fisheye,
                                          color: state.invoiceHeaderBool == '1'
                                              ? Color(0xffEA5504)
                                              : Color(0xffcccccc),
                                          size: setWidth(40),
                                        ),
                                        SizedBox(
                                          width: setWidth(20),
                                        ),
                                        Text(
                                          '个人/非企业',
                                          style: TextStyle(
                                            color: Color(0xff2B2B2B),
                                            fontSize: 14,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  SizedBox(width: setWidth(56)),
                                  InkWell(
                                    onTap: () {
                                      print('！！！不需要发票选择事件！！！');
                                      if (state.invoiceHeaderBool != '0') {
                                        state.invoiceHeaderBool = '0';
                                        setState(() {});
                                      }
                                    },
                                    child: Row(
                                      children: [
                                        Icon(
                                          state.invoiceHeaderBool == '1'
                                              ? Icons.panorama_fisheye
                                              : Icons.check_circle,
                                          color: state.invoiceHeaderBool == '1'
                                              ? Color(0xffcccccc)
                                              : Color(0xffEA5504),
                                          size: setWidth(40),
                                        ),
                                        SizedBox(
                                          width: setWidth(20),
                                        ),
                                        Text(
                                          '企业',
                                          style: TextStyle(
                                            color: Color(0xff303030),
                                            fontSize: 14,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                        Container(
                          color: Colors.white,
                          padding: EdgeInsets.only(
                            top: setWidth(10),
                            left: setWidth(32),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              // 发票名称
                              Row(
                                children: [
                                  Container(
                                    height: setWidth(86),
                                    width: setWidth(150),
                                    alignment: Alignment.centerLeft,
                                    child: Text(
                                      '发票名称',
                                      style: TextStyle(
                                        color: Color(0xff666666),
                                        fontSize: 13,
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    child: Container(
                                      height: setWidth(86),
                                      child: TextField(
                                        controller: state.invoiceNameController,
                                        maxLines: 1,
                                        style: TextStyle(
                                          color: Color(0xff222222),
                                          fontSize: 13,
                                        ),
                                        // onChanged: (text) {
                                        //   logic.whetherAvailableClick();
                                        // },
                                        // enabled: false,
                                        decoration: InputDecoration(
                                          contentPadding: EdgeInsets.zero,
                                          hintText: '请输入发票名称',
                                          hintStyle: TextStyle(
                                            color: Color(0xff999999),
                                            fontSize: 13,
                                          ),
                                          enabledBorder: OutlineInputBorder(
                                            // 设置输入框可编辑时的边框样式
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(
                                                    0)), // 设置边框四个角的弧度
                                            borderSide: BorderSide(
                                              // 用来配置边框的样式
                                              color:
                                                  Colors.transparent, // 设置边框的颜色
                                              width: setWidth(1), // 设置边框的粗细
                                            ),
                                          ),
                                          focusedBorder: OutlineInputBorder(
                                            // 用来配置输入框获取焦点时的颜色
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(
                                                    0)), // 设置边框四个角的弧度
                                            borderSide: BorderSide(
                                              // 用来配置边框的样式
                                              color:
                                                  Colors.transparent, // 设置边框的颜色
                                              width: setWidth(1), // 设置边框的粗细
                                            ),
                                          ),
                                          // disabledBorder: OutlineInputBorder( // 设置输入框可编辑时的边框样式
                                          //   borderRadius: BorderRadius.all(Radius.circular(0)),  // 设置边框四个角的弧度
                                          //   borderSide: BorderSide(  // 用来配置边框的样式
                                          //     color: Colors.transparent,  // 设置边框的颜色
                                          //     width: setWidth(1),  // 设置边框的粗细
                                          //   ),
                                          // ),
                                        ),
                                      ),
                                    ),
                                  ),
                                  SizedBox(width: setWidth(22)),
                                ],
                              ),
                              Divider(
                                height: setWidth(1),
                                indent: 0,
                                endIndent: 0,
                                color: Color(0xffEFEFEF),
                              ),
                              // 税号
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Row(
                                    children: [
                                      Container(
                                        height: setWidth(86),
                                        width: setWidth(150),
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          '税号',
                                          style: TextStyle(
                                            color: Color(0xff666666),
                                            fontSize: 13,
                                          ),
                                        ),
                                      ),
                                      Expanded(
                                        child: Container(
                                          height: setWidth(86),
                                          child: TextField(
                                            controller:
                                                state.dutyParagraphController,
                                            maxLines: 1,
                                            maxLength: 30,
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 13,
                                            ),
                                            decoration: InputDecoration(
                                              counterText: '',
                                              contentPadding: EdgeInsets.zero,
                                              hintText: '请输入纳税人识别号',
                                              hintStyle: TextStyle(
                                                color: Color(0xff999999),
                                                fontSize: 13,
                                              ),
                                              enabledBorder: OutlineInputBorder(
                                                // 设置输入框可编辑时的边框样式
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                              focusedBorder: OutlineInputBorder(
                                                // 用来配置输入框获取焦点时的颜色
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: setWidth(22)),
                                    ],
                                  )),
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Divider(
                                    height: setWidth(1),
                                    indent: 0,
                                    endIndent: 0,
                                    color: Color(0xffEFEFEF),
                                  )),
                              // 企业地址
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Padding(
                                    padding: EdgeInsets.symmetric(
                                        vertical: setWidth(24)),
                                    child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(150),
                                          alignment: Alignment.centerLeft,
                                          child: Text(
                                            '企业地址',
                                            style: TextStyle(
                                              color: Color(0xff666666),
                                              fontSize: 13,
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          child: Container(
                                            child: TextField(
                                              controller: state
                                                  .businessAddressController,
                                              maxLines: 3,
                                              style: TextStyle(
                                                color: Color(0xff222222),
                                                fontSize: 13,
                                              ),
                                              decoration: InputDecoration(
                                                contentPadding: EdgeInsets.zero,
                                                hintText: '请输入企业注册地址',
                                                hintStyle: TextStyle(
                                                  color: Color(0xff999999),
                                                  fontSize: 13,
                                                ),
                                                enabledBorder:
                                                    OutlineInputBorder(
                                                  // 设置输入框可编辑时的边框样式
                                                  borderRadius:
                                                      BorderRadius.all(
                                                          Radius.circular(
                                                              0)), // 设置边框四个角的弧度
                                                  borderSide: BorderSide(
                                                    // 用来配置边框的样式
                                                    color: Colors
                                                        .transparent, // 设置边框的颜色
                                                    width:
                                                        setWidth(1), // 设置边框的粗细
                                                  ),
                                                ),
                                                focusedBorder:
                                                    OutlineInputBorder(
                                                  // 用来配置输入框获取焦点时的颜色
                                                  borderRadius:
                                                      BorderRadius.all(
                                                          Radius.circular(
                                                              0)), // 设置边框四个角的弧度
                                                  borderSide: BorderSide(
                                                    // 用来配置边框的样式
                                                    color: Colors
                                                        .transparent, // 设置边框的颜色
                                                    width:
                                                        setWidth(1), // 设置边框的粗细
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                        SizedBox(width: setWidth(22)),
                                      ],
                                    ),
                                  )),
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Divider(
                                    height: setWidth(1),
                                    indent: 0,
                                    endIndent: 0,
                                    color: Color(0xffEFEFEF),
                                  )),
                              // 企业电话
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Row(
                                    children: [
                                      Container(
                                        height: setWidth(86),
                                        width: setWidth(150),
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          '企业电话',
                                          style: TextStyle(
                                            color: Color(0xff666666),
                                            fontSize: 13,
                                          ),
                                        ),
                                      ),
                                      Expanded(
                                        child: Container(
                                          height: setWidth(86),
                                          child: TextField(
                                            controller: state
                                                .enterpriseTelephoneController,
                                            maxLines: 1,
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 13,
                                            ),
                                            keyboardType: TextInputType.phone,
                                            decoration: InputDecoration(
                                              contentPadding: EdgeInsets.zero,
                                              hintText: '请输入企业注册电话',
                                              hintStyle: TextStyle(
                                                color: Color(0xff999999),
                                                fontSize: 13,
                                              ),
                                              enabledBorder: OutlineInputBorder(
                                                // 设置输入框可编辑时的边框样式
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                              focusedBorder: OutlineInputBorder(
                                                // 用来配置输入框获取焦点时的颜色
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: setWidth(22)),
                                    ],
                                  )),
                              Visibility(
                                  visible: state.invoiceHeaderBool == '2',
                                  child: Divider(
                                    height: setWidth(1),
                                    indent: 0,
                                    endIndent: 0,
                                    color: Color(0xffEFEFEF),
                                  )),
                              // 开户银行
                              Visibility(
                                  visible: state.invoiceHeaderBool == '2',
                                  child: Row(
                                    children: [
                                      Container(
                                        height: setWidth(86),
                                        width: setWidth(150),
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          '开户银行',
                                          style: TextStyle(
                                            color: Color(0xff666666),
                                            fontSize: 13,
                                          ),
                                        ),
                                      ),
                                      Expanded(
                                        child: Container(
                                          height: setWidth(86),
                                          child: TextField(
                                            controller:
                                                state.bankOfDepositController,
                                            maxLines: 1,
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 13,
                                            ),
                                            decoration: InputDecoration(
                                              contentPadding: EdgeInsets.zero,
                                              hintText: '请输入企业开户银行',
                                              hintStyle: TextStyle(
                                                color: Color(0xff999999),
                                                fontSize: 13,
                                              ),
                                              enabledBorder: OutlineInputBorder(
                                                // 设置输入框可编辑时的边框样式
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                              focusedBorder: OutlineInputBorder(
                                                // 用来配置输入框获取焦点时的颜色
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: setWidth(22)),
                                    ],
                                  )),
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Divider(
                                    height: setWidth(1),
                                    indent: 0,
                                    endIndent: 0,
                                    color: Color(0xffEFEFEF),
                                  )),
                              // 银行账号
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Row(
                                    children: [
                                      Container(
                                        height: setWidth(86),
                                        width: setWidth(150),
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          '银行账号',
                                          style: TextStyle(
                                            color: Color(0xff666666),
                                            fontSize: 13,
                                          ),
                                        ),
                                      ),
                                      Expanded(
                                        child: Container(
                                          height: setWidth(86),
                                          child: TextField(
                                            controller:
                                                state.bankAccountController,
                                            maxLines: 1,
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 13,
                                            ),
                                            keyboardType: TextInputType.number,
                                            decoration: InputDecoration(
                                              contentPadding: EdgeInsets.zero,
                                              hintText: '请输入企业银行账号',
                                              hintStyle: TextStyle(
                                                color: Color(0xff999999),
                                                fontSize: 13,
                                              ),
                                              enabledBorder: OutlineInputBorder(
                                                // 设置输入框可编辑时的边框样式
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                              focusedBorder: OutlineInputBorder(
                                                // 用来配置输入框获取焦点时的颜色
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(
                                                        0)), // 设置边框四个角的弧度
                                                borderSide: BorderSide(
                                                  // 用来配置边框的样式
                                                  color: Colors
                                                      .transparent, // 设置边框的颜色
                                                  width: setWidth(1), // 设置边框的粗细
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: setWidth(22)),
                                    ],
                                  )),
                              Visibility(
                                  visible: state.invoiceHeaderBool == '0',
                                  child: Divider(
                                    height: setWidth(1),
                                    indent: 0,
                                    endIndent: 0,
                                    color: Color(0xffEFEFEF),
                                  )),
                              // 是否默认
                              Container(
                                height: setWidth(86),
                                child: InkWell(
                                  onTap: () {
                                    print('！！！纸质发票选择事件！！！');
                                    state.whetherDefaultBool =
                                        !state.whetherDefaultBool;
                                    setState(() {});
                                  },
                                  child: Row(
                                    children: [
                                      Icon(
                                        state.whetherDefaultBool
                                            ? Icons.check_circle
                                            : Icons.panorama_fisheye,
                                        color: state.whetherDefaultBool
                                            ? Color(0xffEA5504)
                                            : Color(0xffcccccc),
                                        size: setWidth(40),
                                      ),
                                      SizedBox(
                                        width: setWidth(20),
                                      ),
                                      Text(
                                        '默认',
                                        style: TextStyle(
                                          color: Color(0xff2B2B2B),
                                          fontSize: 14,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                InkWell(
                  onTap: () {
                    print('保存点击事件');
                    logic.addOrEditorClick();
                  },
                  child: Container(
                    height: setWidth(90),
                    alignment: Alignment.center,
                    color: Color(0xffea5504),
                    child: Text(
                      '保存',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 15,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ));
      },
    );

  }
}
